package com.code.day20;


import java.io.*;

public class Demo12Serializable {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        method();//序列化流
        read();//反序列化流
    }
    public  static  void method() throws IOException {
        ObjectOutputStream objectOutputStream =
                new ObjectOutputStream(new FileOutputStream("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo5.txt"));
        Person person = new Person("张三",18);
        objectOutputStream.writeObject(person);
        objectOutputStream.close();
    }

    public static void read() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream =
                new ObjectInputStream(new FileInputStream("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo5.txt"));
        Object o = objectInputStream.readObject();
        Person person = (Person) o;
        System.out.println(person);
     }

}
